const app = getApp();
var config = require('../../utils/config.js')

Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    list: []
  },
  onLoad: function () {
  },
  onReady:function(){
    this.net_subscribeList()
  },
  switchSex: function (e) {
    let sid = e.currentTarget.id
    let value = e.detail.value ? 1:0
    this.net_subscribeEdit(sid,value)
  },
  net_subscribeList: function () {
    var that = this
    let uid = wx.getStorageSync('uid')

    wx.request({
      url: config.siteURL + '/api/Subscribe/subscribeList',
      data: {
        uid: uid
      },
      method: 'GET', 
      success: function(res){
        that.setData({
          list: res.data.data
        })
        that.onLoad()
      },
      fail: function() {
        // fail
      },
      complete: function() {
        // complete
      }
    })
  },
  net_subscribeEdit: function(sid, status) {

    wx.request({
      url: config.siteURL + '/api/Subscribe/subscribeEdit',
      data: {
        id: sid,
        status: status
      },
      method: 'GET', 
      success: function(res){
        wx.showToast({
          title: '操作成功',
          icon: 'loading',
          duration: 1000
        })
  
        setTimeout(function () {
          wx.hideToast()
        }, 1000)
      },
      fail: function() {
        // fail
      },
      complete: function() {
        // complete
      }
    })
  }
})